package com.study.cloud.controller;

import com.study.cloud.feign.PaymentService;
import com.study.cloud.pojo.CommonResult;
import com.study.cloud.pojo.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequestWrapper;
import java.util.HashMap;

/**
 * @Author：lk
 * @Date：2023/6/30 15:31
 */
@RestController
@Slf4j
public class OrderController {

    //调用支付订单服务端的ip+端口号
    public static final String PAYMENT_URL = "http://service-payment";

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private PaymentService paymentService;

    //创建支付订单的接口
    @GetMapping("/consumer/payment/create")
    public CommonResult<Payment> create(Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/payment/create", payment, CommonResult.class);
    }

    //获取id获取支付订单
    @GetMapping("/consumer/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAYMENT_URL + "/payment/get/" + id, CommonResult.class);

    }


    //创建支付订单的接口,feign
    @GetMapping("feign/consumer/payment/get/{id}")
    public CommonResult<Payment> getPaymentFeign(@PathVariable("id") Long id) {
        return paymentService.queryById(id);
    }

    public static void main(String[] args) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("refId","2");
        Long refId = (Long)map.get("refId");
        System.out.println(refId);

    }

}
